<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JSON跨域</title>
</head>

<body>
    <p>用户名</p>
    <input type="text">
    <script>
        const p = document.querySelector('p');
        const input = document.querySelector('input')
        //声明handle 函数
        function handle(data) {
            input.sty1e.border = "solid 1px red";
            //修改p标签的提示文本
            p.innerHTML = data.msg;
        }
        / /绑定事件
        input.onblur = function () {
            //获取用户的输入值
            let username = this.value;
            //向服务器端发送请求检测用户名是否存在
            //1.创建script 标签
            const script = document.createElement('script')
            //2. 设置标签的src 属性
            script.src = 'http://127.0.0.1:8000/check-username'
            //3.将script 插入到文档中
            document.body.appendChild(script);
        }
    </script>
</body>

</html>